/*
* Copyright 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "GLESv2Decoder.h"

#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

static inline void* SafePointerFromUInt(GLuint value) {
  return (void*)(uintptr_t)value;
}

GLESv2Decoder::GLESv2Decoder()
{
    m_contextData = NULL;
    m_GL2library = NULL;
}

GLESv2Decoder::~GLESv2Decoder()
{
    delete m_GL2library;
}

void gl2_nullstub() {}

void  GLESv2Decoder::check_Entry()
{
	if (!this->glActiveTexture) (glActiveTexture) =(glActiveTexture_server_proc_t)gl2_nullstub;
	if(!glAttachShader)  glAttachShader = (glAttachShader_server_proc_t)gl2_nullstub;
	if(!glBindAttribLocation)  glBindAttribLocation = (glBindAttribLocation_server_proc_t)gl2_nullstub;
	if(!glBindBuffer)  glBindBuffer = (glBindBuffer_server_proc_t)gl2_nullstub;
	if(!glBindFramebuffer)  glBindFramebuffer = (glBindFramebuffer_server_proc_t)gl2_nullstub;
	if(!glBindRenderbuffer)  glBindRenderbuffer = (glBindRenderbuffer_server_proc_t)gl2_nullstub;
	if(!glBindTexture)  glBindTexture = (glBindTexture_server_proc_t)gl2_nullstub;
	if(!glBlendColor)  glBlendColor = (glBlendColor_server_proc_t)gl2_nullstub;
	if(!glBlendEquation)  glBlendEquation = (glBlendEquation_server_proc_t)gl2_nullstub;
	if(!glBlendEquationSeparate)  glBlendEquationSeparate = (glBlendEquationSeparate_server_proc_t)gl2_nullstub;
	if(!glBlendFunc)  glBlendFunc = (glBlendFunc_server_proc_t)gl2_nullstub;
	if(!glBlendFuncSeparate)  glBlendFuncSeparate = (glBlendFuncSeparate_server_proc_t)gl2_nullstub;
	if(!glBufferData)  glBufferData = (glBufferData_server_proc_t)gl2_nullstub;
	if(!glBufferSubData)  glBufferSubData = (glBufferSubData_server_proc_t)gl2_nullstub;
	if(!glCheckFramebufferStatus)  glCheckFramebufferStatus = (glCheckFramebufferStatus_server_proc_t)gl2_nullstub;
	if(!glClear)  glClear = (glClear_server_proc_t)gl2_nullstub;
	if(!glClearColor)  glClearColor = (glClearColor_server_proc_t)gl2_nullstub;
	if(!glClearDepthf)  glClearDepthf = (glClearDepthf_server_proc_t)gl2_nullstub;
	if(!glClearStencil)  glClearStencil = (glClearStencil_server_proc_t)gl2_nullstub;
	if(!glColorMask)  glColorMask = (glColorMask_server_proc_t)gl2_nullstub;
	if(!glCompileShader)  glCompileShader = (glCompileShader_server_proc_t)gl2_nullstub;
	if(!glCompressedTexImage2D)  glCompressedTexImage2D = (glCompressedTexImage2D_server_proc_t)gl2_nullstub;
	if(!glCompressedTexSubImage2D)  glCompressedTexSubImage2D = (glCompressedTexSubImage2D_server_proc_t)gl2_nullstub;
	if(!glCopyTexImage2D)  glCopyTexImage2D = (glCopyTexImage2D_server_proc_t)gl2_nullstub;
	if(!glCopyTexSubImage2D)  glCopyTexSubImage2D = (glCopyTexSubImage2D_server_proc_t)gl2_nullstub;
	if(!glCreateProgram)  glCreateProgram = (glCreateProgram_server_proc_t)gl2_nullstub;
	if(!glCreateShader)  glCreateShader = (glCreateShader_server_proc_t)gl2_nullstub;
	if(!glCullFace)  glCullFace = (glCullFace_server_proc_t)gl2_nullstub;
	if(!glDeleteBuffers)  glDeleteBuffers = (glDeleteBuffers_server_proc_t)gl2_nullstub;
	if(!glDeleteFramebuffers)  glDeleteFramebuffers = (glDeleteFramebuffers_server_proc_t)gl2_nullstub;
	if(!glDeleteProgram)  glDeleteProgram = (glDeleteProgram_server_proc_t)gl2_nullstub;
	if(!glDeleteRenderbuffers)  glDeleteRenderbuffers = (glDeleteRenderbuffers_server_proc_t)gl2_nullstub;
	if(!glDeleteShader)  glDeleteShader = (glDeleteShader_server_proc_t)gl2_nullstub;
	if(!glDeleteTextures)  glDeleteTextures = (glDeleteTextures_server_proc_t)gl2_nullstub;
	if(!glDepthFunc)  glDepthFunc = (glDepthFunc_server_proc_t)gl2_nullstub;
	if(!glDepthMask)  glDepthMask = (glDepthMask_server_proc_t)gl2_nullstub;
	if(!glDepthRangef)  glDepthRangef = (glDepthRangef_server_proc_t)gl2_nullstub;
	if(!glDetachShader)  glDetachShader = (glDetachShader_server_proc_t)gl2_nullstub;
	if(!glDisable)  glDisable = (glDisable_server_proc_t)gl2_nullstub;
	if(!glDisableVertexAttribArray)  glDisableVertexAttribArray = (glDisableVertexAttribArray_server_proc_t)gl2_nullstub;
	if(!glDrawArrays)  glDrawArrays = (glDrawArrays_server_proc_t)gl2_nullstub;
	if(!glDrawElements)  glDrawElements = (glDrawElements_server_proc_t)gl2_nullstub;
	if(!glEnable)  glEnable = (glEnable_server_proc_t)gl2_nullstub;
	if(!glEnableVertexAttribArray)  glEnableVertexAttribArray = (glEnableVertexAttribArray_server_proc_t)gl2_nullstub;
	if(!glFinish)  glFinish = (glFinish_server_proc_t)gl2_nullstub;
	if(!glFlush)  glFlush = (glFlush_server_proc_t)gl2_nullstub;
	if(!glFramebufferRenderbuffer)  glFramebufferRenderbuffer = (glFramebufferRenderbuffer_server_proc_t)gl2_nullstub;
	if(!glFramebufferTexture2D)  glFramebufferTexture2D = (glFramebufferTexture2D_server_proc_t)gl2_nullstub;
	if(!glFrontFace)  glFrontFace = (glFrontFace_server_proc_t)gl2_nullstub;
	if(!glGenBuffers)  glGenBuffers = (glGenBuffers_server_proc_t)gl2_nullstub;
	if(!glGenerateMipmap)  glGenerateMipmap = (glGenerateMipmap_server_proc_t)gl2_nullstub;
	if(!glGenFramebuffers)  glGenFramebuffers = (glGenFramebuffers_server_proc_t)gl2_nullstub;
	if(!glGenRenderbuffers)  glGenRenderbuffers = (glGenRenderbuffers_server_proc_t)gl2_nullstub;
	if(!glGenTextures)  glGenTextures = (glGenTextures_server_proc_t)gl2_nullstub;
	if(!glGetActiveAttrib)  glGetActiveAttrib = (glGetActiveAttrib_server_proc_t)gl2_nullstub;
	if(!glGetActiveUniform)  glGetActiveUniform = (glGetActiveUniform_server_proc_t)gl2_nullstub;
	if(!glGetAttachedShaders)  glGetAttachedShaders = (glGetAttachedShaders_server_proc_t)gl2_nullstub;
	if(!glGetAttribLocation)  glGetAttribLocation = (glGetAttribLocation_server_proc_t)gl2_nullstub;
	if(!glGetBooleanv)  glGetBooleanv = (glGetBooleanv_server_proc_t)gl2_nullstub;
	if(!glGetBufferParameteriv)  glGetBufferParameteriv = (glGetBufferParameteriv_server_proc_t)gl2_nullstub;
	if(!glGetError)  glGetError = (glGetError_server_proc_t)gl2_nullstub;
	if(!glGetFloatv)  glGetFloatv = (glGetFloatv_server_proc_t)gl2_nullstub;
	if(!glGetFramebufferAttachmentParameteriv)  glGetFramebufferAttachmentParameteriv = (glGetFramebufferAttachmentParameteriv_server_proc_t)gl2_nullstub;
	if(!glGetIntegerv)  glGetIntegerv = (glGetIntegerv_server_proc_t)gl2_nullstub;
	if(!glGetProgramiv)  glGetProgramiv = (glGetProgramiv_server_proc_t)gl2_nullstub;
	if(!glGetProgramInfoLog)  glGetProgramInfoLog = (glGetProgramInfoLog_server_proc_t)gl2_nullstub;
	if(!glGetRenderbufferParameteriv)  glGetRenderbufferParameteriv = (glGetRenderbufferParameteriv_server_proc_t)gl2_nullstub;
	if(!glGetShaderiv)  glGetShaderiv = (glGetShaderiv_server_proc_t)gl2_nullstub;
	if(!glGetShaderInfoLog)  glGetShaderInfoLog = (glGetShaderInfoLog_server_proc_t)gl2_nullstub;
	if(!glGetShaderPrecisionFormat)  glGetShaderPrecisionFormat = (glGetShaderPrecisionFormat_server_proc_t)gl2_nullstub;
	if(!glGetShaderSource)  glGetShaderSource = (glGetShaderSource_server_proc_t)gl2_nullstub;
	if(!glGetString)  glGetString = (glGetString_server_proc_t)gl2_nullstub;
	if(!glGetTexParameterfv)  glGetTexParameterfv = (glGetTexParameterfv_server_proc_t)gl2_nullstub;
	if(!glGetTexParameteriv)  glGetTexParameteriv = (glGetTexParameteriv_server_proc_t)gl2_nullstub;
	if(!glGetUniformfv)  glGetUniformfv = (glGetUniformfv_server_proc_t)gl2_nullstub;
	if(!glGetUniformiv)  glGetUniformiv = (glGetUniformiv_server_proc_t)gl2_nullstub;
	if(!glGetUniformLocation)  glGetUniformLocation = (glGetUniformLocation_server_proc_t)gl2_nullstub;
	if(!glGetVertexAttribfv)  glGetVertexAttribfv = (glGetVertexAttribfv_server_proc_t)gl2_nullstub;
	if(!glGetVertexAttribiv)  glGetVertexAttribiv = (glGetVertexAttribiv_server_proc_t)gl2_nullstub;
	if(!glGetVertexAttribPointerv)  glGetVertexAttribPointerv = (glGetVertexAttribPointerv_server_proc_t)gl2_nullstub;
	if(!glHint)  glHint = (glHint_server_proc_t)gl2_nullstub;
	if(!glIsBuffer)  glIsBuffer = (glIsBuffer_server_proc_t)gl2_nullstub;
	if(!glIsEnabled)  glIsEnabled = (glIsEnabled_server_proc_t)gl2_nullstub;
	if(!glIsFramebuffer)  glIsFramebuffer = (glIsFramebuffer_server_proc_t)gl2_nullstub;
	if(!glIsProgram)  glIsProgram = (glIsProgram_server_proc_t)gl2_nullstub;
	if(!glIsRenderbuffer)  glIsRenderbuffer = (glIsRenderbuffer_server_proc_t)gl2_nullstub;
	if(!glIsShader)  glIsShader = (glIsShader_server_proc_t)gl2_nullstub;
	if(!glIsTexture)  glIsTexture = (glIsTexture_server_proc_t)gl2_nullstub;
	if(!glLineWidth)  glLineWidth = (glLineWidth_server_proc_t)gl2_nullstub;
	if(!glLinkProgram)  glLinkProgram = (glLinkProgram_server_proc_t)gl2_nullstub;
	if(!glPixelStorei)  glPixelStorei = (glPixelStorei_server_proc_t)gl2_nullstub;
	if(!glPolygonOffset)  glPolygonOffset = (glPolygonOffset_server_proc_t)gl2_nullstub;
	if(!glReadPixels)  glReadPixels = (glReadPixels_server_proc_t)gl2_nullstub;
	if(!glReleaseShaderCompiler)  glReleaseShaderCompiler = (glReleaseShaderCompiler_server_proc_t)gl2_nullstub;
	if(!glRenderbufferStorage)  glRenderbufferStorage = (glRenderbufferStorage_server_proc_t)gl2_nullstub;
	if(!glSampleCoverage)  glSampleCoverage = (glSampleCoverage_server_proc_t)gl2_nullstub;
	if(!glScissor)  glScissor = (glScissor_server_proc_t)gl2_nullstub;
	if(!glShaderBinary)  glShaderBinary = (glShaderBinary_server_proc_t)gl2_nullstub;
	if(!glShaderSource)  glShaderSource = (glShaderSource_server_proc_t)gl2_nullstub;
	if(!glStencilFunc)  glStencilFunc = (glStencilFunc_server_proc_t)gl2_nullstub;
	if(!glStencilFuncSeparate)  glStencilFuncSeparate = (glStencilFuncSeparate_server_proc_t)gl2_nullstub;
	if(!glStencilMask)  glStencilMask = (glStencilMask_server_proc_t)gl2_nullstub;
	if(!glStencilMaskSeparate)  glStencilMaskSeparate = (glStencilMaskSeparate_server_proc_t)gl2_nullstub;
	if(!glStencilOp)  glStencilOp = (glStencilOp_server_proc_t)gl2_nullstub;
	if(!glStencilOpSeparate)  glStencilOpSeparate = (glStencilOpSeparate_server_proc_t)gl2_nullstub;
	if(!glTexImage2D)  glTexImage2D = (glTexImage2D_server_proc_t)gl2_nullstub;
	if(!glTexParameterf)  glTexParameterf = (glTexParameterf_server_proc_t)gl2_nullstub;
	if(!glTexParameterfv)  glTexParameterfv = (glTexParameterfv_server_proc_t)gl2_nullstub;
	if(!glTexParameteri)  glTexParameteri = (glTexParameteri_server_proc_t)gl2_nullstub;
	if(!glTexParameteriv)  glTexParameteriv = (glTexParameteriv_server_proc_t)gl2_nullstub;
	if(!glTexSubImage2D)  glTexSubImage2D = (glTexSubImage2D_server_proc_t)gl2_nullstub;
	if(!glUniform1f)  glUniform1f = (glUniform1f_server_proc_t)gl2_nullstub;
	if(!glUniform1fv)  glUniform1fv = (glUniform1fv_server_proc_t)gl2_nullstub;
	if(!glUniform1i)  glUniform1i = (glUniform1i_server_proc_t)gl2_nullstub;
	if(!glUniform1iv)  glUniform1iv = (glUniform1iv_server_proc_t)gl2_nullstub;
	if(!glUniform2f)  glUniform2f = (glUniform2f_server_proc_t)gl2_nullstub;
	if(!glUniform2fv)  glUniform2fv = (glUniform2fv_server_proc_t)gl2_nullstub;
	if(!glUniform2i)  glUniform2i = (glUniform2i_server_proc_t)gl2_nullstub;
	if(!glUniform2iv)  glUniform2iv = (glUniform2iv_server_proc_t)gl2_nullstub;
	if(!glUniform3f)  glUniform3f = (glUniform3f_server_proc_t)gl2_nullstub;
	if(!glUniform3fv)  glUniform3fv = (glUniform3fv_server_proc_t)gl2_nullstub;
	if(!glUniform3i)  glUniform3i = (glUniform3i_server_proc_t)gl2_nullstub;
	if(!glUniform3iv)  glUniform3iv = (glUniform3iv_server_proc_t)gl2_nullstub;
	if(!glUniform4f)  glUniform4f = (glUniform4f_server_proc_t)gl2_nullstub;
	if(!glUniform4fv)  glUniform4fv = (glUniform4fv_server_proc_t)gl2_nullstub;
	if(!glUniform4i)  glUniform4i = (glUniform4i_server_proc_t)gl2_nullstub;
	if(!glUniform4iv)  glUniform4iv = (glUniform4iv_server_proc_t)gl2_nullstub;
	if(!glUniformMatrix2fv)  glUniformMatrix2fv = (glUniformMatrix2fv_server_proc_t)gl2_nullstub;
	if(!glUniformMatrix3fv)  glUniformMatrix3fv = (glUniformMatrix3fv_server_proc_t)gl2_nullstub;
	if(!glUniformMatrix4fv)  glUniformMatrix4fv = (glUniformMatrix4fv_server_proc_t)gl2_nullstub;
	if(!glUseProgram)  glUseProgram = (glUseProgram_server_proc_t)gl2_nullstub;
	if(!glValidateProgram)  glValidateProgram = (glValidateProgram_server_proc_t)gl2_nullstub;
	if(!glVertexAttrib1f)  glVertexAttrib1f = (glVertexAttrib1f_server_proc_t)gl2_nullstub;
	if(!glVertexAttrib1fv)  glVertexAttrib1fv = (glVertexAttrib1fv_server_proc_t)gl2_nullstub;
	if(!glVertexAttrib2f)  glVertexAttrib2f = (glVertexAttrib2f_server_proc_t)gl2_nullstub;
	if(!glVertexAttrib2fv)  glVertexAttrib2fv = (glVertexAttrib2fv_server_proc_t)gl2_nullstub;
	if(!glVertexAttrib3f)  glVertexAttrib3f = (glVertexAttrib3f_server_proc_t)gl2_nullstub;
	if(!glVertexAttrib3fv)  glVertexAttrib3fv = (glVertexAttrib3fv_server_proc_t)gl2_nullstub;
	if(!glVertexAttrib4f)  glVertexAttrib4f = (glVertexAttrib4f_server_proc_t)gl2_nullstub;
	if(!glVertexAttrib4fv)  glVertexAttrib4fv = (glVertexAttrib4fv_server_proc_t)gl2_nullstub;
	if(!glVertexAttribPointer)  glVertexAttribPointer = (glVertexAttribPointer_server_proc_t)gl2_nullstub;
	if(!glViewport)  glViewport = (glViewport_server_proc_t)gl2_nullstub;
	if(!glEGLImageTargetTexture2DOES)  glEGLImageTargetTexture2DOES = (glEGLImageTargetTexture2DOES_server_proc_t)gl2_nullstub;
	if(!glEGLImageTargetRenderbufferStorageOES)  glEGLImageTargetRenderbufferStorageOES = (glEGLImageTargetRenderbufferStorageOES_server_proc_t)gl2_nullstub;
	if(!glGetProgramBinaryOES)  glGetProgramBinaryOES = (glGetProgramBinaryOES_server_proc_t)gl2_nullstub;
	if(!glProgramBinaryOES)  glProgramBinaryOES = (glProgramBinaryOES_server_proc_t)gl2_nullstub;
	if(!glMapBufferOES)  glMapBufferOES = (glMapBufferOES_server_proc_t)gl2_nullstub;
	if(!glUnmapBufferOES)  glUnmapBufferOES = (glUnmapBufferOES_server_proc_t)gl2_nullstub;
	if(!glTexImage3DOES)  glTexImage3DOES = (glTexImage3DOES_server_proc_t)gl2_nullstub;
	if(!glTexSubImage3DOES)  glTexSubImage3DOES = (glTexSubImage3DOES_server_proc_t)gl2_nullstub;
	if(!glCopyTexSubImage3DOES)  glCopyTexSubImage3DOES = (glCopyTexSubImage3DOES_server_proc_t)gl2_nullstub;
	if(!glCompressedTexImage3DOES)  glCompressedTexImage3DOES = (glCompressedTexImage3DOES_server_proc_t)gl2_nullstub;
	if(!glCompressedTexSubImage3DOES)  glCompressedTexSubImage3DOES = (glCompressedTexSubImage3DOES_server_proc_t)gl2_nullstub;
	if(!glFramebufferTexture3DOES)  glFramebufferTexture3DOES = (glFramebufferTexture3DOES_server_proc_t)gl2_nullstub;
	if(!glBindVertexArrayOES)  glBindVertexArrayOES = (glBindVertexArrayOES_server_proc_t)gl2_nullstub;
	if(!glDeleteVertexArraysOES)  glDeleteVertexArraysOES = (glDeleteVertexArraysOES_server_proc_t)gl2_nullstub;
	if(!glGenVertexArraysOES)  glGenVertexArraysOES = (glGenVertexArraysOES_server_proc_t)gl2_nullstub;
	if(!glIsVertexArrayOES)  glIsVertexArrayOES = (glIsVertexArrayOES_server_proc_t)gl2_nullstub;
	if(!glDiscardFramebufferEXT)  glDiscardFramebufferEXT = (glDiscardFramebufferEXT_server_proc_t)gl2_nullstub;
	if(!glMultiDrawArraysEXT)  glMultiDrawArraysEXT = (glMultiDrawArraysEXT_server_proc_t)gl2_nullstub;
	if(!glMultiDrawElementsEXT)  glMultiDrawElementsEXT = (glMultiDrawElementsEXT_server_proc_t)gl2_nullstub;
	if(!glGetPerfMonitorGroupsAMD)  glGetPerfMonitorGroupsAMD = (glGetPerfMonitorGroupsAMD_server_proc_t)gl2_nullstub;
	if(!glGetPerfMonitorCountersAMD)  glGetPerfMonitorCountersAMD = (glGetPerfMonitorCountersAMD_server_proc_t)gl2_nullstub;
	if(!glGetPerfMonitorGroupStringAMD)  glGetPerfMonitorGroupStringAMD = (glGetPerfMonitorGroupStringAMD_server_proc_t)gl2_nullstub;
	if(!glGetPerfMonitorCounterStringAMD)  glGetPerfMonitorCounterStringAMD = (glGetPerfMonitorCounterStringAMD_server_proc_t)gl2_nullstub;
	if(!glGetPerfMonitorCounterInfoAMD)  glGetPerfMonitorCounterInfoAMD = (glGetPerfMonitorCounterInfoAMD_server_proc_t)gl2_nullstub;
	if(!glGenPerfMonitorsAMD)  glGenPerfMonitorsAMD = (glGenPerfMonitorsAMD_server_proc_t)gl2_nullstub;
	if(!glDeletePerfMonitorsAMD)  glDeletePerfMonitorsAMD = (glDeletePerfMonitorsAMD_server_proc_t)gl2_nullstub;
	if(!glSelectPerfMonitorCountersAMD)  glSelectPerfMonitorCountersAMD = (glSelectPerfMonitorCountersAMD_server_proc_t)gl2_nullstub;
	if(!glBeginPerfMonitorAMD)  glBeginPerfMonitorAMD = (glBeginPerfMonitorAMD_server_proc_t)gl2_nullstub;
	if(!glEndPerfMonitorAMD)  glEndPerfMonitorAMD = (glEndPerfMonitorAMD_server_proc_t)gl2_nullstub;
	if(!glGetPerfMonitorCounterDataAMD)  glGetPerfMonitorCounterDataAMD = (glGetPerfMonitorCounterDataAMD_server_proc_t)gl2_nullstub;
	if(!glRenderbufferStorageMultisampleIMG)  glRenderbufferStorageMultisampleIMG = (glRenderbufferStorageMultisampleIMG_server_proc_t)gl2_nullstub;
	if(!glFramebufferTexture2DMultisampleIMG)  glFramebufferTexture2DMultisampleIMG = (glFramebufferTexture2DMultisampleIMG_server_proc_t)gl2_nullstub;
	if(!glDeleteFencesNV)  glDeleteFencesNV = (glDeleteFencesNV_server_proc_t)gl2_nullstub;
	if(!glGenFencesNV)  glGenFencesNV = (glGenFencesNV_server_proc_t)gl2_nullstub;
	if(!glIsFenceNV)  glIsFenceNV = (glIsFenceNV_server_proc_t)gl2_nullstub;
	if(!glTestFenceNV)  glTestFenceNV = (glTestFenceNV_server_proc_t)gl2_nullstub;
	if(!glGetFenceivNV)  glGetFenceivNV = (glGetFenceivNV_server_proc_t)gl2_nullstub;
	if(!glFinishFenceNV)  glFinishFenceNV = (glFinishFenceNV_server_proc_t)gl2_nullstub;
	if(!glSetFenceNV)  glSetFenceNV = (glSetFenceNV_server_proc_t)gl2_nullstub;
	if(!glCoverageMaskNV)  glCoverageMaskNV = (glCoverageMaskNV_server_proc_t)gl2_nullstub;
	if(!glCoverageOperationNV)  glCoverageOperationNV = (glCoverageOperationNV_server_proc_t)gl2_nullstub;
	if(!glGetDriverControlsQCOM)  glGetDriverControlsQCOM = (glGetDriverControlsQCOM_server_proc_t)gl2_nullstub;
	if(!glGetDriverControlStringQCOM)  glGetDriverControlStringQCOM = (glGetDriverControlStringQCOM_server_proc_t)gl2_nullstub;
	if(!glEnableDriverControlQCOM)  glEnableDriverControlQCOM = (glEnableDriverControlQCOM_server_proc_t)gl2_nullstub;
	if(!glDisableDriverControlQCOM)  glDisableDriverControlQCOM = (glDisableDriverControlQCOM_server_proc_t)gl2_nullstub;
	if(!glExtGetTexturesQCOM)  glExtGetTexturesQCOM = (glExtGetTexturesQCOM_server_proc_t)gl2_nullstub;
	if(!glExtGetBuffersQCOM)  glExtGetBuffersQCOM = (glExtGetBuffersQCOM_server_proc_t)gl2_nullstub;
	if(!glExtGetRenderbuffersQCOM)  glExtGetRenderbuffersQCOM = (glExtGetRenderbuffersQCOM_server_proc_t)gl2_nullstub;
	if(!glExtGetFramebuffersQCOM)  glExtGetFramebuffersQCOM = (glExtGetFramebuffersQCOM_server_proc_t)gl2_nullstub;
	if(!glExtGetTexLevelParameterivQCOM)  glExtGetTexLevelParameterivQCOM = (glExtGetTexLevelParameterivQCOM_server_proc_t)gl2_nullstub;
	if(!glExtTexObjectStateOverrideiQCOM)  glExtTexObjectStateOverrideiQCOM = (glExtTexObjectStateOverrideiQCOM_server_proc_t)gl2_nullstub;
	if(!glExtGetTexSubImageQCOM)  glExtGetTexSubImageQCOM = (glExtGetTexSubImageQCOM_server_proc_t)gl2_nullstub;
	if(!glExtGetBufferPointervQCOM)  glExtGetBufferPointervQCOM = (glExtGetBufferPointervQCOM_server_proc_t)gl2_nullstub;
	if(!glExtGetShadersQCOM)  glExtGetShadersQCOM = (glExtGetShadersQCOM_server_proc_t)gl2_nullstub;
	if(!glExtGetProgramsQCOM)  glExtGetProgramsQCOM = (glExtGetProgramsQCOM_server_proc_t)gl2_nullstub;
	if(!glExtIsProgramBinaryQCOM)  glExtIsProgramBinaryQCOM = (glExtIsProgramBinaryQCOM_server_proc_t)gl2_nullstub;
	if(!glExtGetProgramBinarySourceQCOM)  glExtGetProgramBinarySourceQCOM = (glExtGetProgramBinarySourceQCOM_server_proc_t)gl2_nullstub;
	if(!glStartTilingQCOM)  glStartTilingQCOM = (glStartTilingQCOM_server_proc_t)gl2_nullstub;
	if(!glEndTilingQCOM)  glEndTilingQCOM = (glEndTilingQCOM_server_proc_t)gl2_nullstub;
	if(!glVertexAttribPointerData)  glVertexAttribPointerData = (glVertexAttribPointerData_server_proc_t)gl2_nullstub;
	if(!glVertexAttribPointerOffset)  glVertexAttribPointerOffset = (glVertexAttribPointerOffset_server_proc_t)gl2_nullstub;
	if(!glDrawElementsOffset)  glDrawElementsOffset = (glDrawElementsOffset_server_proc_t)gl2_nullstub;
	if(!glDrawElementsData)  glDrawElementsData = (glDrawElementsData_server_proc_t)gl2_nullstub;
	if(!glGetCompressedTextureFormats)  glGetCompressedTextureFormats = (glGetCompressedTextureFormats_server_proc_t)gl2_nullstub;
	if(!glShaderString)  glShaderString = (glShaderString_server_proc_t)gl2_nullstub;
	if(!glFinishRoundTrip)  glFinishRoundTrip = (glFinishRoundTrip_server_proc_t)gl2_nullstub;
}

void *GLESv2Decoder::s_getProc(const char *name, void *userData)
{
    GLESv2Decoder *ctx = (GLESv2Decoder *) userData;

    if (ctx == NULL || ctx->m_GL2library == NULL) {
        return NULL;
    }

    void *func = NULL;
#ifdef USE_EGL_GETPROCADDRESS
    func = (void *) eglGetProcAddress(name);
#endif
    if (func == NULL) {
        func = (void *) ctx->m_GL2library->findSymbol(name);
    }
    return func;
}

int GLESv2Decoder::initGL(get_proc_func_t getProcFunc, void *getProcFuncData)
{

	this->initDispatchByName(getProcFunc, getProcFuncData);

    glGetCompressedTextureFormats = s_glGetCompressedTextureFormats;
    glVertexAttribPointerData = s_glVertexAttribPointerData;
    glVertexAttribPointerOffset = s_glVertexAttribPointerOffset;

    glDrawElementsOffset = s_glDrawElementsOffset;
    glDrawElementsData = s_glDrawElementsData;
    glShaderString = s_glShaderString;
    glFinishRoundTrip = s_glFinishRoundTrip;
    return 0;

}

int GLESv2Decoder::s_glFinishRoundTrip(void *self)
{
    GLESv2Decoder *ctx = (GLESv2Decoder *)self;
    ctx->glFinish();
    return 0;
}

void GLESv2Decoder::s_glGetCompressedTextureFormats(void *self, int count, GLint *formats)
{
    GLESv2Decoder *ctx = (GLESv2Decoder *) self;

    int nFormats;
    ctx->glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &nFormats);
    if (nFormats > count) {
        fprintf(stderr, "%s: GetCompressedTextureFormats: The requested number of formats does not match the number that is reported by OpenGL\n", __FUNCTION__);
    } else {
        ctx->glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
    }
}

void GLESv2Decoder::s_glVertexAttribPointerData(void *self, GLuint indx, GLint size, GLenum type,
                                             GLboolean normalized, GLsizei stride,  void * data, GLuint datalen)
{
    GLESv2Decoder *ctx = (GLESv2Decoder *) self;
    if (ctx->m_contextData != NULL) {
        ctx->m_contextData->storePointerData(indx, data, datalen);
        // note - the stride of the data is always zero when it comes out of the codec.
        // See gl2.attrib for the packing function call.
        ctx->glVertexAttribPointer(indx, size, type, normalized, 0, ctx->m_contextData->pointerData(indx));
    }
}

void GLESv2Decoder::s_glVertexAttribPointerOffset(void *self, GLuint indx, GLint size, GLenum type,
                                               GLboolean normalized, GLsizei stride,  GLuint data)
{
    GLESv2Decoder *ctx = (GLESv2Decoder *) self;
    ctx->glVertexAttribPointer(indx, size, type, normalized, stride, SafePointerFromUInt(data));
}


void GLESv2Decoder::s_glDrawElementsData(void *self, GLenum mode, GLsizei count, GLenum type, void * data, GLuint datalen)
{
    GLESv2Decoder *ctx = (GLESv2Decoder *)self;
    ctx->glDrawElements(mode, count, type, data);
}


void GLESv2Decoder::s_glDrawElementsOffset(void *self, GLenum mode, GLsizei count, GLenum type, GLuint offset)
{
    GLESv2Decoder *ctx = (GLESv2Decoder *)self;
    ctx->glDrawElements(mode, count, type, SafePointerFromUInt(offset));
}

void GLESv2Decoder::s_glShaderString(void *self, GLuint shader, const GLchar* string, GLsizei len)
{
    GLESv2Decoder *ctx = (GLESv2Decoder *)self;
    ctx->glShaderSource(shader, 1, &string, NULL);
}
